<script type="text/javascript">
function deleteUser(userid){
	$.post(
			'<?php echo site_url('usermanagecontroller/deleteUser');?>',
			{user:userid,active:0},
			function(result){
				alert('Data ' + userid + ' berhasil dihapus');
				location.reload();
			}
	);
}
</script>
<br/>
<?php if(isset($message)) echo '<span style="color:rgb(255,0,0);font-family:Arial,Helvetica,Sans;font-size:9pt;">'.$message.'</span>'?>
<br/><br/>
<a href="<?php echo site_url('usermanagecontroller/addUser')?>">Tambah User</a>
<table cellpadding="3" cellspacing="0" width="55%" style="border-collapse: collapse;border-bottom:3px solid black;border-top:3px solid black;border-left:3px solid black;border-right:3px solid black;" class="record" bordercolor="#CCCCCC" border="1">
	<thead>
        <tr style="background-color:#FFF; color:#000000;" align="center">
            <td colspan="7" height="25"><strong>DAFTAR USER</strong></td>
        </tr>
        <tr class="tableCellHeader">
        	<th>No.</th>
            <th>User ID</th>
            <th>FullName</th>
            <th>System Grade</th>
            <th>&nbsp;</th>
        </tr>
    </thead>
    <tbody id="datauser"><?php
		$i = 0; 
		if(count($users)>0){
			foreach($users as $data){
				$style = "";
				if($i%2 == 0)$style="cellDefault"; else $style="cellAlternate";				
            	echo '<tr class="'.$style.'">';
            	echo '<td style="padding-left:5px;padding-right:5px;text-align:right;">&nbsp;'.($i + 1).'.&nbsp;</td>';
                echo '<td><input type="text" id="txtUserid_'.$i.'" value="'.$data->userid.'" class="flat-textbox-string" /></td>';
                echo '<td><input type="text" id="txtFullName_'.$i.'" value="'.$data->fullname.'" class="flat-textbox-string" /></td>';
                echo '<td>'.$data->description.'</td>';

                if($this->session->userdata('grade') == 0)
				{
					echo '<td><button id="hapususer" onclick="javascript:deleteUser(\''.$data->userid.'\');">Hapus</button>&nbsp;|&nbsp;<button onclick="javascript:window.location = \''.site_url('usermanagecontroller/editUser').'/'.$data->userid.'\';" id="hapususer">Edit</button></td>';
				} 
                
                echo '<input type="hidden" id="txtPassword_'.$i.'" value="'.$data->password.'" class="flat-textbox-string" />';                
                echo '<input type="hidden" id="txtGradeID_'.$i.'" value="'.$data->gradeid.'" class="flat-textbox-string" />';
            	echo '</tr>';        
        		$i++;
        	}
		} else{
            echo "<tr>";
            echo "<td colspan='9' style='text-align:center;color:red;'>No Data To Display</td>";
            echo "</tr>";
    } ?></tbody>
</table>
<br/>
<div id="user" class="holder"></div>